package cn.hongyu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
public class DataChange {
    //自定义类型转换器 日期类型 看配置
    //啥也不配置示范
    @RequestMapping(value = "/date1")
    @ResponseBody
    void rset1(@RequestParam(value = "d") Date date) {
        //localhost:8999/date1?d=2018/12/21 正确
        //http://localhost:8999/date1?d=2018-12-21 400格式错误
        System.out.println(date);
    }

    //先创建一个类实现接口Converter 在cn.hongyu.converter包下
    //在配置中声明刚刚定义的类(转换器)
    //在<annotation-driven> 中引用转换器
    @RequestMapping(value = "/date2")
    @ResponseBody
    void rset2(@RequestParam(value = "d") Date date) {
        //localhost:8999/date1?d=2018/12/21 正确
        //http://localhost:8999/date1?d=2018-12-21 400格式错误
        System.out.println(date);
    }
}
